import random
from time import sleep
import uiautomation
import pyautogui
from tools.sjqd_way import write_data_from_excel


class fuwudengji():
        name = random.randrange(1,101)
        age = random.randrange(10,71)
        sex = random.choice(['男','女'])
        ID1 = random.randrange(1960,2024)
        ID2 = random.randrange(1000,9999)
        tel = random.randrange(10000000,999999999)
        his = uiautomation.WindowControl(searchDepth=1, Name='科玛奇医院信息管理系统')  # 锁定窗口
        xm = his.CustomControl(AutomationId='mzghWin',ClassName='MenZhenGuaHaoView').EditControl(AutomationId='txtName', ClassName='TextBox') #姓名
        xb = his.CustomControl(AutomationId='mzghWin',ClassName='MenZhenGuaHaoView').EditControl(AutomationId='PART_TextBox', ClassName='TextBox',foundIndex=3) #性别
        fb = his.CustomControl(AutomationId='mzghWin', ClassName='MenZhenGuaHaoView').EditControl(AutomationId='PART_TextBox', ClassName='TextBox', foundIndex=1)  # 费别
        nl = his.CustomControl(AutomationId='mzghWin',ClassName='MenZhenGuaHaoView').EditControl(AutomationId='tbNianling', ClassName='TextBox') #年龄
        SFID = his.CustomControl(AutomationId='mzghWin',ClassName='MenZhenGuaHaoView').EditControl(AutomationId='txtSFZH', ClassName='TextBox') #身份证号码
        fwks = his.CustomControl(AutomationId='mzghWin',ClassName='MenZhenGuaHaoView').EditControl(AutomationId='PART_TextBox', ClassName='TextBox',foundIndex=4) #服务科室
        ys = his.CustomControl(AutomationId='mzghWin',ClassName='MenZhenGuaHaoView').EditControl(AutomationId='PART_TextBox', ClassName='TextBox',foundIndex=5) #医生
        dz = his.CustomControl(AutomationId='mzghWin',ClassName='MenZhenGuaHaoView').EditControl(AutomationId='txtZhuZhi', ClassName='TextBox') #地址
        bc= his.CustomControl(AutomationId='mzghWin',ClassName='MenZhenGuaHaoView').ButtonControl(AutomationId='savebtn', ClassName='Button') #保存
        cz= his.CustomControl(AutomationId='mzghWin',ClassName='MenZhenGuaHaoView').ButtonControl(AutomationId='clearbtn', ClassName='Button') #重置
        xjzf = his.CheckBoxControl(ClassName='CheckBox',Name='现金支付')

#输入姓名
        def input_name(self):
                self.xm.Click()
                pyautogui.hotkey('ctrl', 'a')
                pyautogui.hotkey('back')
                self.xm.SendKeys('测试患者{}'.format(self.name))
                ceshihuanzhe = self.xm.GetValuePattern().Value
                write_data_from_excel(ceshihuanzhe)

#选择性别
        def choose_sex(self):
                self.xb.Click()
                self.xb.SendKeys('{}'.format(self.sex))
                sleep(1)
                pyautogui.press('enter')
#输入年龄
        def input_age(self):
                self.nl.SendKeys('{}'.format(self.age))

#输入身份证号码
        def input_id(self):
                self.SFID.SendKeys("510623{}0909{}".format(self.ID1,self.ID2))
#输入电话号码
        def input_tel(self):
                self.SFID.Click()
                pyautogui.press('tab')
                pyautogui.typewrite('159{}'.format(self.tel))
#选择服务科室
        def choose_fwks(self,fwks):
                fwks1 = str(fwks)
                self.fwks.DoubleClick()
                self.fwks.SendKeys(fwks1)
                pyautogui.press('enter')

#选择医生
        def choose_ys(self,doctor):
                doctor1 = doctor
                self.ys.DoubleClick()
                self.ys.SendKeys(doctor1)
                pyautogui.press('enter')

#输入地址
        def input_dz(self,adress):
                self.dz.SendKeys(adress)

#点击保存
        def click_bc_btn(self):
                self.bc.Click()

#点击关闭
        def click_xjzf_btn(self):
                self.xjzf.Click()


#创建多个患者
        def creat_hz(self,fwks,doctor,adress):
                fwks1 = str(fwks)
                doctor1 = str(doctor)
                adress1 = str(adress)
                self.input_name()
                self.choose_sex()
                self.input_id()
                self.choose_fwks(fwks1)
                self.choose_ys(doctor1)
                self.input_dz(adress1)
                self.click_bc_btn()
